package com.tom.dronedefense;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class CodeInTheHole extends Activity {
	
	private RelativeLayout relativeLayout;
	SurfaceHolder holder;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        //God-like container
        relativeLayout = new RelativeLayout(this);
        relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        
        /** Tower Menu Definition */
        LinearLayout towerMenuContainer = new LinearLayout(this);
        towerMenuContainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT));
        towerMenuContainer.setId(321);
        towerMenuContainer.setOrientation(LinearLayout.VERTICAL);
        towerMenuContainer.setBackgroundColor(Color.WHITE);
        //Lets add three towers - name these better
        ImageView tower1 = new ImageView(this);
        tower1.setImageResource(R.drawable.aoe_tower);
        tower1.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        ImageView tower2 = new ImageView(this);
        tower2.setImageResource(R.drawable.power_tower);
        tower2.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        ImageView tower3 = new ImageView(this);
        tower3.setImageResource(R.drawable.support_tower);
        tower3.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

        towerMenuContainer.addView(tower1);
        towerMenuContainer.addView(tower2);
        towerMenuContainer.addView(tower3);

        /** Stats Bar Definition */
        LinearLayout statsBarContainer = new LinearLayout(this);
        statsBarContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        statsBarContainer.setId(4123);
        statsBarContainer.setBackgroundColor(Color.WHITE);
        TextView text1 = new TextView(this);
        text1.setText("Score: 10,234");
        text1.setId(1);
        TextView text2 = new TextView(this);
        text2.setText("Coin: 1234c");
        text2.setId(2);
        TextView text3 = new TextView(this);
        text3.setText("Lives: 4");
        text3.setId(3);
        statsBarContainer.addView(text1);
        statsBarContainer.addView(text2);
//        RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        statsBarContainer.addView(text3);

        /** GameBoard Definition */
        GameBoardView gbv = new GameBoardView(this);
        gbv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        gbv.setBackgroundColor(Color.RED);
        gbv.setId(1244);

        /** Status Update Bar */
        final LinearLayout statusBar = new LinearLayout(this);
        statusBar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        statusBar.setBackgroundColor(Color.BLUE);
        final TextView ach = new TextView(this);
        ach.setText("you unlocked something really cool");
        statusBar.addView(ach);
        
        
        
        /** Add to master*/
        RelativeLayout.LayoutParams genLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        genLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        relativeLayout.addView(towerMenuContainer,genLayoutParams);
        genLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        genLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        relativeLayout.addView(statsBarContainer,genLayoutParams);
        genLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        genLayoutParams.addRule(RelativeLayout.ABOVE, statsBarContainer.getId());
        genLayoutParams.addRule(RelativeLayout.LEFT_OF, towerMenuContainer.getId());
        relativeLayout.addView(gbv,genLayoutParams);
        genLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        genLayoutParams.addRule(RelativeLayout.BELOW, gbv.getId());
        genLayoutParams.addRule(RelativeLayout.RIGHT_OF,statsBarContainer.getId());
        relativeLayout.addView(statusBar,genLayoutParams);
        
        /** LayoutAnimation Take One*/
        final AnimationSet set = new AnimationSet(true);
        
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(4000);
        set.addAnimation(animation);
        
        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
        								   Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
        animation.setDuration(3000);
        set.addAnimation(animation);
        
        // Create an anonymous implementation of OnClickListener
        OnClickListener l = new OnClickListener() {
            public void onClick(View v) {
            		ach.startAnimation(set);
            }
        };
        
        OnClickListener l2 = new OnClickListener() {
            public void onClick(View v) {
            	Toast toast = Toast.makeText(getApplicationContext(), "this is and achievement, nice!", 1000);
            	toast.show();
            }
        };
        
        statusBar.setOnClickListener(l);
        gbv.setOnClickListener(l2);
        setContentView(relativeLayout);
    }
}
